package com.xjm;


import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * com.xjm
 * <h4>Servlet入门</h4>
 * @author xiejiemin
 * @create 2020/10/16
 */
@WebServlet("/hello")
@Slf4j
public class HelloServlet extends HttpServlet {
    /**
     * 测试Servlet的调用顺序以及生命周期
     */
    @Override
    public void init() {
        log.info("servlet init");
    }

    /**
     * 测试Servlet的调用顺序以及生命周期
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        log.info("servlet using service method");
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = "自研框架";
        request.setAttribute("name", name);
        request.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(request, response);
        log.info("开始的第一步!");
    }

}
